package org.crumbleworks.crumbchat.client.controller;

import org.crumbleworks.crumbchat.client.console.ConsoleReader;
import org.crumbleworks.crumbchat.common.data.Message;

public class ConsoleController implements ClientControllerInterface {
    private ConsoleReader consoleReader;

    private ClientControllerInterface controller;

    public ConsoleController(ClientControllerInterface controller) {
        this.controller = controller;

        consoleReader = new ConsoleReader(this);
    }

    @Override
    public void connectToServer(String host, String username) {
        controller.connectToServer(host, username);
    }

    @Override
    public void disconnectFromServer(boolean shutdownAfterDisconnect) {
        controller.disconnectFromServer(shutdownAfterDisconnect);
    }

    @Override
    public void sendMessageToServer(String text) {
        controller.sendMessageToServer(text);
    }

    @Override
    public void putMessageToChat(Message message) {
        System.out.println(message.getUsername() + ": " + message.getMessage() + "\n");
    }

    @Override
    public void showConnectError(String host) {
        System.err.println("Konnte keine Verbindung zu '" + host + "' aufbauen");
    }

    @Override
    public void shutdown() {
        consoleReader.stop();
    }

    @Override
    public void parseInput(String input) {
        controller.parseInput(input);
    }
}
